package com.weshare.config;

import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticJobRegistryCenterConfig {
    private static final int ZOOKEEPER_PORT = 2181;
    private static final String ZOOKEEPER_CONNECTION_STRING = "47.112.110.71:" + ZOOKEEPER_PORT;
    private static final String JOB_NAMESPACE = "elastic-job-springboot";

    /**
     * 配置zookeeper
     *
     * @return
     */
    @Bean(initMethod = "init")
    private static CoordinatorRegistryCenter setUpRegistryCenter() {

        ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(ZOOKEEPER_CONNECTION_STRING, JOB_NAMESPACE);
        zookeeperConfiguration.setSessionTimeoutMilliseconds(100);
        CoordinatorRegistryCenter registryCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
        registryCenter.init();
        return registryCenter;
    }
}
